New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@iter-tools/queue

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iter-tools/queue

An es6-style iterable queue

  • 1.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
43
increased by43.33%
Maintainers
1
Weekly downloads
 
Created
Source

@iter-tools/queue

Build Status codecov

A simple es6 linked FIFO queue in the pattern of es6 Map and Set. Includes typescript libdefs. Suitable for node or browser environments. Supports native es imports in node > 13.2.

Usage

const Queue = require('@iter-tools/queue'); // OR
import Queue from '@iter-tools/queue';

const q = new Queue([1, 2, 3]);
q.push(4);
[...q]; // [1, 2, 3, 4]
q.size; // 4
q.shift(); // 1
q.shift(); // 2
q.shift(); // 3
q.shift(); // 4
q.size; // 0
q.shift(); // undefined

Until Typescript supports package exports you must enable esModuleInterop to use this module.

API

/**
 * The values which has been in the queue longest is its head.
 * The most recent addition is the tail.
 */
class Queue<T> {
  /**
   * Returns true if `inst` is a Queue.
   * This does not necessarily imply instanceof, but the check
   * is safe across frame boundaries, as it is done by looking for
   * Queue[Symbol.for('@iter-tools/queue')]
   */
  static isQueue(inst): boolean;

  /**
   * An optional iterable of `values` to be pushed into the queue
   * in sequence. If `null` or `undefined` are passed the queue will
   * have no initial values.
   */
  constructor(values?: Iterable<T>);

  /**
   * The number of values in the queue
   */
  size: number;

  /**
   * Empties the queue of all values.
   */
  clear();

  /**
   * Returns the value at the head of the queue.
   */
  peek(): T | undefined;

  /**
   * Removes the value at the head of the queue and returns it.
   */
  shift(): T | undefined;

  /**
   * Adds `value` at the tail of the queue.
   */
  push(value: T);

  /**
   * Calls `cb(value, index, queue)` for each value in the queue.
   */
  forEach(
    cb: (value: T, index: number, queue: Queue) => any,
  );

  /**
   * Yields sequential 0-based indexes, one for each queued value.
   * The index 0 indicates the head.
   */
  keys(): IterableIterator<number>;

  /**
   * Yields the queued values from head to tail.
   */
  values(): IterableIterator<T>;

  /**
   * Yields `[index, value]` tuples for each value in the queue.
   */
  entries(): IterableIterator<[number, T]>;

  /**
   * The default iterator. Equivalent to `values()`.
   */
  [Symbol.iterator](): IterableIterator<T>;
}

Keywords

FAQs

Package last updated on 15 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc